export {}

// 1.概述
function sumv1(val: string | number): number | string {
  return val
}

function sumv2<T>(val: T): T {
  return val
}
console.log(sumv2(1))
console.log(sumv2('num' as string))
console.log(sumv2(<string>'good'))

type funv2<T> = (val: T) => T
const sumv3: funv2<number> = (val: number) => val
console.log(sumv3(11111))

console.log()
console.log('=======================================================1')
// 2.泛型约束
interface MustLenField {
  length: number
}

function FunV3<T extends MustLenField>(val: T): number {
  return val.length
}
console.log(FunV3('123'))
// 报错
// console.log(FunV3(123))

console.log()
console.log('=======================================================2')
// 3.泛型和类的活用export&import
import { Band } from './MyClass'

const band = new Band<string, string>('faith55555', '1234567890')
console.log(band)
